

/**
 * uni.showActionSheet
 * @param {Array} itemList 选项
 * @param {String} title 标题
 * @returns {Object} {name,index}
 */
function useActionSheet(itemList = [], title = "") {
  return new Promise((resolve, reject) => {
    uni.showActionSheet({
      title,
      itemList,
      success: ({ tapIndex = -1 }) => {
        if (tapIndex === -1) {
          return;
        }

        resolve({ name: itemList[tapIndex] || "", index: tapIndex });
      },
      fail: (error) => {
        console.error(error);
        reject(error);
      },
    });
  });
}

export default useActionSheet;
